package com.wanmait.hotelManage.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wanmait.hotelManage.util.DBHelper;
import com.wanmait.hotelManage.vo.Admin;

public class AdminDAO {
	
	private AdminDAO() {};
	private static AdminDAO admindao=new AdminDAO();
	public static AdminDAO getAdmindao() {
		return admindao;
	}
	public Admin finduserNameandPassword(String username, String password) {
		Admin admin=null;
		Connection conn=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		String sql="select * from admin where username=? and password=?";
		conn=DBHelper.getDBHelper().getConn();
		try {
			ps=conn.prepareStatement(sql);
			ps.setString(1, username);
			ps.setString(2, password);
			rs=ps.executeQuery();
			if(rs.next()) {
			admin=new Admin();
			admin.setId(rs.getInt("id"));
			admin.setUsername(rs.getString("username"));
			admin.setPassword(rs.getString("password"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			DBHelper.getDBHelper().close(rs, ps, conn);
		}
		return admin;
	}
	
}
